import {Component, OnInit} from '@angular/core';
import {MsgChannelService} from "../../channel/msgChannel.service";
import {MsgResult} from "../../../../../models/msg-result";
import {MsgConstants} from "../../../../../constants/constants";
import {Path} from "../../../../../portal/admin/admin-breadcrumb/breadcrumb";
import {PageSubject} from "../../../../../util/page-subject";
import {ResponseUtil} from "../../../../../util/response-util";
import {OneDialogService} from "../../../../../widgets/one-dialog/one-dialog.service";
import {ActivatedRoute, Router} from "@angular/router";

declare var $;

@Component({
  selector: 'app-instance-category',
  templateUrl: './instance-category.component.html',
  styleUrls: ['./instance-category.component.css']
})
export class InstanceCategoryComponent implements OnInit {

  constructor(
    private router : Router,
    private route : ActivatedRoute,
    private pageSubject: PageSubject,
    private channelService : MsgChannelService,
    private dialogService: OneDialogService,
    private responseUtil: ResponseUtil,
  ) {

  }

  alarmObject: Array<any> = [];

  ngOnInit() {
    this.initPage();
    this.pushPage();
  }

  /**
   * 面包屑导航
   */
  pushPage() {
    let path = new Path("报警管理", "");
    this.pageSubject.pushPage("报警实例添加", "选择通道", path);

  }

  /**
   * 返回
   */

  goBack() {
    this.router.navigate(['..'], {relativeTo: this.route});
  }

  /**
   * 初始化页面
   */
  initPage() {
    this.channelService.getAllChannel().subscribe(
      result => this.responseUtil.success(result, this.processGetResult),
      error => this.responseUtil.error(error)
    );
  }

  /**
   * id查询成功后调用
   * @param json
   */
  private processGetResult = (result: MsgResult) => {
    if (result && result.code == MsgConstants.MSG_CODE_OK) {
      this.handleData(result.data);
    }
    if (result && result.code != MsgConstants.MSG_CODE_OK) {
      this.dialogService.info(result.message);
    }
  }

  /**
   * 处理数据
   * @param data
   */
  private handleData(data) {
    this.alarmObject.push(data.national);
    this.alarmObject.push(data.small);
    this.alarmObject.push(data.industry);
    this.alarmObject.push(data.raiseDust);
    this.alarmObject.push(data.lampblack);
    this.alarmObject.push(data.sprayBooth);
    this.alarmObject.push(data.gasStation);
    this.alarmObject.push(data.waterPollution);
    this.alarmObject.push(data.waterSurface);
    this.alarmObject[0].name = "标准站";
    this.alarmObject[1].name = "微型站";
    this.alarmObject[2].name = "工业废气";
    this.alarmObject[3].name = "扬尘";
    this.alarmObject[4].name = "油烟";
    this.alarmObject[5].name = "油漆房";
    this.alarmObject[6].name = "加油站";
    this.alarmObject[7].name = "工业废水";
    this.alarmObject[8].name = "水质断层";

  }


  /**
   * 添加页面跳转
   */
  instanceAdd(id) {
    this.router.navigate(['../add',{id: id}], {relativeTo: this.route});
  }
}
